package icu.cocoon.work.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import icu.cocoon.dao.base.BaseController;
import icu.cocoon.dao.base.Resp;
import icu.cocoon.work.entity.WechatArticle;
import icu.cocoon.work.entity.dto.WechatArticleDTO;
import icu.cocoon.work.pojo.param.ShareParam;
import icu.cocoon.work.pojo.param.WechatArticleSearchParam;
import icu.cocoon.work.service.WechatArticleService;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Cocoon
 * @since 2020-07-30
 */
@RestController
@RequestMapping("/work/wechatArticle")
public class WechatArticleController extends BaseController<WechatArticle, WechatArticleService> {

  @PostMapping("wechatArticleList")
  public Resp<List<WechatArticleDTO>> init(@RequestBody WechatArticleSearchParam param)
      throws UnsupportedEncodingException {
    List<WechatArticleDTO> dtoList = getService().getWechatArticleDTOList(param.getPage(), param.getKeyword(),
        param.getToken(), param.getCookie());
    return Resp.success(dtoList);
  }

  @PostMapping("share")
  public Resp<?> share(@RequestBody ShareParam param) throws JsonProcessingException {
    return Resp.success(getService().shareArticle(param.getToken(),param.getArticleId()));
  }
}

